import numpy as np
import PyQt5
import matplotlib

matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt

matplotlib.rcParams['font.sans-serif'] = ['SimHei']  # 设置中文字体
matplotlib.rcParams["axes.unicode_minus"] = False  # 解决负号显示问题

# 定义PVC管和不锈钢管的性能指标
labels = np.array(['材料特性', '应用领域', '成本因素', '环境影响', '耐用性'])
pvc = np.array([4, 3, 5, 2, 1])
stainless_steel = np.array([5, 4, 2, 4, 5])

# 计算雷达图的角度
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()

# 使雷达图封闭
pvc = np.concatenate((pvc, [pvc[0]]))
stainless_steel = np.concatenate((stainless_steel, [stainless_steel[0]]))
angles += angles[:1]

# 绘制雷达图
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
ax.fill(angles, pvc, color='red', alpha=0.25)
ax.fill(angles, stainless_steel, color='blue', alpha=0.25)

# 绘制标签和图例
ax.set_yticklabels([])
ax.set_xticks(angles[:-1])
ax.set_xticklabels(labels, fontsize=12)

# 设置字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 设置字体为黑体
plt.rcParams['axes.unicode_minus'] = False  # 正确显示负号

plt.legend(['PVC管', '不锈钢管'], loc='upper right', bbox_to_anchor=(0.1, 0.1))
plt.title('PVC管与不锈钢管对比雷达图', fontsize=16, pad=20)

plt.show()
